<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head>



<title>Sphere Online Judge (SPOJ)  - Problem RLM</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-2" id="metatag">
<meta name="Keywords" content="programming, language, algorithm, spoj, contest, contester, Java, C#, Pascal, C, C++, python, ruby, caml, ocaml, perl, haskell, lisp, prolog, fortran, assembler, asembler, functional, online, judge, problem, problemset, ACM">

<link href="https://www.spoj.pl/gfx/favicon.png" rel="shortcut icon" type="image/x-icon">
<link href="https://www.spoj.pl/rss/" rel="alternate" type="application/rss+xml" title="RSS Feed">
<link href="spoj-04908_archivos/common.css" rel="stylesheet" type="text/css" id="theme">
<link href="spoj-04908_archivos/style.css" rel="stylesheet" type="text/css" id="theme">
<link href="spoj-04908_archivos/tooltips.css" rel="stylesheet" type="text/css" id="theme">
<script type="text/javascript" src="spoj-04908_archivos/jquery_002.js"></script>
<style type="text/css">
<!--
.maintable {width: 755px;} 
-->
</style>
<script type="text/javascript" language="javascript">
<!--
function UnCryptMailto(s) {
	var n=0;
	var r="";
	for(var i=0;i<s.length;i++) {		
		n=s.charCodeAt(i); 
		if (n>=8364) {n = 128;}
		r += String.fromCharCode(n+(2));	
	}
	return r;
}
function linkTo_UnCryptMailto(s)	{
	location.href=UnCryptMailto(s);
}
// -->
</script>

</head><body>
<center>
<table class="maintable" id="maintable" cellpadding="10" cellspacing="0">
<tbody><tr>
    <td colspan="2" class="header">
        <table border="0" cellpadding="0" cellspacing="0" width="100%">
        <tbody><tr>
		<td class="headerleft">
		</td><td class="headercenter">
<h1><img alt="Sphere Online Judge" title="Sphere Online Judge" src="spoj-04908_archivos/sphere-spoj-small.png" style="margin-top: -4px; margin-bottom: -4px;" border="0"></h1>
		</td>
		<td class="headerright">
	</td></tr>
	</tbody></table>
    </td>
</tr>
<tr><td class="menu" valign="top" width="92">


<div class="menucmd"><a href="https://www.spoj.pl/logout"><b style="font-weight: normal;">Log Out</b></a><br><b style="font-weight: normal; margin-right: -100px;">dncampo</b><br><hr><a href="https://www.spoj.pl/myaccount">my account</a><br><a href="https://www.spoj.pl/tutorials">tutorials</a><br><br><a href="https://www.spoj.pl/status">status</a><br><a href="https://www.spoj.pl/submit">submit</a><br><a href="https://www.spoj.pl/problems/classical/sort=0,start=1100">problems</a><br><a href="https://www.spoj.pl/search">search</a><br><br><a href="https://www.spoj.pl/">news</a><br><a href="https://www.spoj.pl/contests">contests</a><br><a href="https://www.spoj.pl/ranks/">ranks</a><br><br><a href="https://www.spoj.pl/forum">forum</a><br><a href="https://www.spoj.pl/comments">comments</a><br><a href="https://www.spoj.pl/credits">credits</a><br><hr></div><a href="https://www.spoj.pl/problems/classical/sort=0,start=1100"></a><br>

	<div class="time">
Server time:</div>
<div class="time">
2009-12-31
<br>
<b>23 : 52 : 27</b>
</div>

</td><td style="padding: 0px; width: 100%;" class="content0" valign="top">
        <table cellpadding="0" cellspacing="0" width="100%">
        <tbody><tr>
                <td style="padding: 0px;" colspan="2"><center>
                                
                </center></td>
        </tr>
        <tr>
                <td class="content" style="padding: 10px;" width="99%">
	<div id="personal_msg_job_application">
		<div id="personal_msg_job_application_title">
			<p style="padding: 0px; font-size: 10px; margin-top: 6px; margin-right: 6px;" align="right">
				<a style="color: rgb(160, 180, 190);" href="#" onclick="JavaScript: $('#personal_msg_job_application_content').toggle(); return false;" class="bigger_link">
				SPOJ Recruitment is now available - click here to find out more
				</a>
			</p>
		</div>
		<div id="personal_msg_job_application_content" class="personal_message" style="display: none;">
			<h3>SPOJ Recruitment</h3>
			<p align="left">
			SPOJ has introduced new functionality which allows users to find
			attractive jobs. All you need to do is to fill <a href="https://www.spoj.pl/job/application/dncampo">this form</a>
			and then wait for employers to hire you.
			<br><br>
			You can always go to your job application by clicking <a href="https://www.spoj.pl/myaccount">my account</a> and then following the
			
			<a href="https://www.spoj.pl/job/application/dncampo">My job application</a> link.
			</p>
			<a href="https://www.spoj.pl/job/application/dncampo/" class="bigger_link">Go to your job application</a> or
			<a href="#" onclick="JavaScript: $('#personal_msg_job_application_content').hide(); return false;" class="bigger_link">hide this message</a>
			
			<p align="left">
			To hide this message permanently go to 
			<a href="https://www.spoj.pl/job/application/dncampo">
			your job application</a>, edit it and click <i>Hide message permanently</i> button.
			</p>
		</div>
	</div>



<script type="text/javascript" src="spoj-04908_archivos/jquery_003.js"></script>
<script type="text/javascript" src="spoj-04908_archivos/jquery.js"></script>
<script type="text/javascript" src="spoj-04908_archivos/jquery_004.js"></script>



 <!-- wykorzystywane w pcontent.html (by wiele) -->

<table class="problems" width="100%">
<tbody><tr class="navigation">
<td><a href="https://www.spoj.pl/submit/RLM/">Submit</a></td>
<td><a href="https://www.spoj.pl/status/RLM,dncampo/">My submissions</a></td>
<td><a href="https://www.spoj.pl/status/RLM/">All submissions</a></td>
<td><a href="https://www.spoj.pl/ranks/RLM/">Best solutions</a></td>
<td><a href="https://www.spoj.pl/problems/RLM.ps">PS</a></td>
<td><a href="https://www.spoj.pl/problems/RLM.pdf">PDF</a></td>
<td><a href="https://www.spoj.pl/problems/classical/sort=0,start=1100">Back to list</a></td>
</tr>
</tbody></table>

<div class="prob">


<!-- plik z pomoca kontekstowa (cxhelp_*) dziedziczony po pindex.html -->


<script type="text/javascript" src="spoj-04908_archivos/ASCIIMathMLwFallback.js"></script>
<script type="text/javascript" src="spoj-04908_archivos/ASCIIsvgPI.html"></script>
<script type="text/javascript">
<!--
var AScgiloc = 'http://www.imathas.com/imathas/filter/graph/svgimg.php';
var AMTcgiloc = "/files/gif/";
-->
</script>

<table style="margin-top: 10px;" width="100%">
<tbody><tr>
	<td>
		<h2>SPOJ Problem Set (classical)</h2>
				<h1>4908. Run-Length Mathematics</h1>
		<h2>Problem code: RLM</h2>
	</td>
	</tr>
</tbody></table>

<p align="justify">
</p><p>Run-length encoding of a number replaces a run of digits (that
is, a sequence of consecutive equivalent digits) with the number of
digits followed by the digit itself. For example, 44455 would become
3425 (three fours, two fives). Note that run-length encoding does not
necessarily shorten the length of the data: 11 becomes 21, and 42
becomes 1412. If a number has more than nine consecutive digits of the
same type, the encoding is done greedily: each run grabs as many digits
as it can, so 111111111111111 is encoded as 9161.</p>
<p>Implement an integer arithmetic calculator that takes operands and
gives results in run-length format. You should support addition,
subtraction, multiplication, and division. You won't have to divide by
zero or deal with negative numbers.</p>
<h3>Input/Output</h3>
<p>The input will consist of several test cases, one per line. For each
test case, compute the run-length mathematics expression and output the
original expression and the result, as shown in the examples. The
(decimal) representation of all operands and results will fit in signed
64-bit integers.</p>
<h3>Example</h3>
<pre><strong>Input:</strong>
11 + 11
988726 - 978625
12 * 41
1124 / 1112
13 * 33
15 / 16

<strong>Output:</strong>
11 + 11 = 12
988726 - 978625 = 919111
12 * 41 = 42
1124 / 1112 = 1112
13 * 33 = 39
15 / 16 = 10
</pre>

<hr>
<table style="margin-bottom: 10px;" class="probleminfo" align="left" border="0" cellpadding="0" cellspacing="0">
<tbody><tr><td>Added by:</td><td><a href="https://www.spoj.pl/users/mlpalii">Miorel Palii</a></td></tr>
<tr><td>Date:</td><td>2009-10-04</td></tr>
<tr><td>Time limit:</td><td>2s
</td></tr>
<tr><td>Source limit:</td><td>4096B</td></tr>
<tr><td>Languages:</td><td>All except: ERL TECS </td></tr>
<tr><td>Resource:</td><td>University of Florida Local Contest - April 13, 2009</td></tr>	
</tbody></table>
<div id="ccontent">

<hr style="clear: both;">
<a href="#" onclick="toggleComments(); return false;"><span id="comments_sh">hide</span> comments</a><br>

<a id="comments"></a>
<table id="comments_table" width="100%">
		<tbody><tr>
		<td colspan="2">
				</td>
	</tr>
	
	<script language="JavaScript">
	<!--
	$(document).ready(function(){
        $('.pager_link').bind('click', function(me){
                var href=$(me.currentTarget).attr('href');
		$('#ccontent').animate({opacity: 0.5},1);
                $.ajax({
                        type: "GET",
                        url: href+",ajax=1",
                        contentType: "application/x-www-form-urlencoded;charset=ISO-8859-2",
                        success: function(data){
                                $('#ccontent').html(data);
				$('#ccontent').animate({opacity: 1.0},1);
                        },
                        error: function(err){
                                alert('error');
                        }
                });
                return false;
        });
	});
	-->
	</script>
	

			
	<tr>
		<td colspan="2" class="comm comm_odd ">
		<font>
		2009-12-21 19:09:24 <b><a href="https://www.spoj.pl/users/honey">VIMAL RAJ SHARMA</a></b> 
		</font>
								<br>
				RE 
<br>
<br>@ D
<br>
<br>no actually the INPUTS are also in RLM 
<br>so 
<br>11 = 1
<br>11 = 1
<br>
<br>1 + 1 = 2
<br>hence it is written as 12
<br>
						</td>
	</tr>
				
	<tr>
		<td colspan="2" class="comm comm_even ">
		<font>
		2009-11-26 08:17:47 <b><a href="https://www.spoj.pl/users/mlpalii">Miorel Palii</a></b> 
		</font>
								<br>
Generally I would agree. Unfortunately many contests do not provide
such information. This problem is meant to prepare you for such
contests ;)
<br>
<br>And for this particular problem, the time limit doesn't seem to be
an issue, as I write this there are nearly 300 submissions and only 4
TLEs. </td>
	</tr>
				
	<tr>
		<td colspan="2" class="comm comm_odd ">
		<font>
		2009-11-04 17:46:02 <b><a href="https://www.spoj.pl/users/sesh">Seshadri R</a></b> 
		</font>
								<br>
Instead of saying several test cases, it would be helpful if an
approximate number is specified. This will enable us to prepare test
data of the stated magnitude and test whether our submission would
suffer TLE or not </td>
	</tr>
				
	<tr>
		<td colspan="2" class="comm comm_even ">
		<font>
		2009-10-16 23:55:40 <b><a href="https://www.spoj.pl/users/mlpalii">Miorel Palii</a></b> 
		</font>
								<br>
				Hi, thanks for the comments. And yes, there will be no negative numbers or division by zero.
						</td>
	</tr>
				
	<tr>
		<td colspan="2" class="comm comm_odd ">
		<font>
		2009-10-16 23:55:40 <b><a href="https://www.spoj.pl/users/zukow">:D</a></b> 
		</font>
								<br>
				"22 becomes 12" I think that's an error. It should be either "2 becomes 12" or "22 becomes 22"
						</td>
	</tr>
				
	<tr>
		<td colspan="2" class="comm comm_even ">
		<font>
		2009-10-16 23:55:40 <b><a href="https://www.spoj.pl/users/hosam_samy">hosam samy</a></b> 
		</font>
								<br>
				What will be the answer if the input is :
<br>1110 / 10 ?
<br>
<br>Re by Blue Mary: no test case with divisor 0.
				<br><br>
		<b>Last edit: 2009-10-10 12:29:28</b>
						</td>
	</tr>
				
	<tr>
		<td colspan="2" class="comm comm_odd ">
		<font>
		2009-10-16 23:55:40 <b><a href="https://www.spoj.pl/users/abhijith">abhijith reddy d</a></b> 
		</font>
								<br>
				How are negitive numbers represented ??
<br>
<br>Re by Blue Mary: no such test case.
				<br><br>
		<b>Last edit: 2009-10-09 11:34:34</b>
						</td>
	</tr>
			
</tbody></table>


<script language="javascript" type="text/javascript">
<!--
function getCookieVal (offset) {
        var endstr = document.cookie.indexOf (";", offset);
        if (endstr == -1) { 
                endstr = document.cookie.length; 
        }
        return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg) {
      return getCookieVal (j);
      }
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break; 
    }
  return null;
}

function toggleComments() {
        var a = document.getElementById('comments_table');
        var d = a.style.display;
        if( d == "" || d == "block" ){
                d = "none";
                document.getElementById('comments_sh').innerHTML = 'show';
        } else {
                d = "block";
                document.getElementById('comments_sh').innerHTML = 'hide';
        }
        a.style.display = d;
        document.cookie="comments_table="+d+"; path=/;";
}

if( GetCookie('comments_table') == 'none' ){
        document.getElementById('comments_sh').innerHTML = 'show';
        document.getElementById('comments_table').style.display = 'hide';
}

-->
</script>


</div>
<table width="100%">
                <tbody><tr>
                <td colspan="2" height="20px"></td>
        </tr>
        <form method="post" action="/comment/RLM/add/"></form>
        <tr> <td style="padding-left: 5px;" colspan="2">Leave a Comment</td> </tr>
        <tr>
                <td valign="top"></td>
                <td><textarea name="content" cols="40" rows="3"></textarea></td>
        </tr>
                <tr>
                <td colspan="2" style="padding-left: 5px;">
                        <input value="Publish" type="submit">
                        <input name="pcode" value="RLM" type="hidden">
                </td>
        </tr>
<tr>
<td colspan="2" class="smallgrey" style="padding-left: 5px;">
Notes:
<br>1. Don't post any source code here.
<br>2. Please be careful, leave short comments only. Don't spam here.
<br>3. For more discussion (hints, ideas, solutions) please visit our <a href="https://www.spoj.pl/forum">forum</a>.
<br>4. Authors of the problems are allowed to delete the post and use html code here (e.g. to provide some useful links).
</td>
</tr>
        
        </tbody></table>

</div>
        </td>
</tr><tr>
        <td style="padding: 0px;" colspan="2"><center>
                
</center></td>
</tr>
</tbody></table>
</td>
</tr>

<tr>
<td colspan="2" class="footer">

<script language="javascript" type="text/javascript">
<!--
function swapSheet(sheet, caller) {
    document.getElementById('theme').href=sheet;
    document.cookie="css_0="+sheet+"; path=/;";
    caller.href="#bottom";
}

function setWidth(w, caller) {
    document.getElementById('maintable').style.width=w;
    document.cookie="res="+w+"; path=/;";
    caller.href="#bottom";
}
//-->

</script>
        <table width="100%">
    <tbody><tr>
	<td class="cfooter" align="left" width="10%">
	<a href="https://www.spoj.pl/info/">About SPOJ</a>
	</td>
	<td class="cfooter" align="center">
	    page size:
	    <a href="https://www.spoj.pl/?rsl=755px" onclick="setWidth('755px', this)">800x600</a>
	    <a href="https://www.spoj.pl/?rsl=980px" onclick="setWidth('980px', this)">1024x768</a>
	    <a href="https://www.spoj.pl/?rsl=100%" onclick="setWidth('100%', this)">Full</a>
	    &nbsp;&nbsp;
	    theme:
	    <a href="https://www.spoj.pl/?css=/themes/skin1.css" onclick="swapSheet('/themes/skin1.css', this)">olive</a>
	    <a href="https://www.spoj.pl/?css=/themes/skin2.css" onclick="swapSheet('/themes/skin2.css', this)">banana</a>
	    <a href="https://www.spoj.pl/?css=/themes/skin3.css" onclick="swapSheet('/themes/skin3.css', this)">plum</a>
	</td>
		<td class="cfooter" align="center">
		 <span title="The discussion channel of the Sphere Online Judge community.">
		 <a href="irc://irc.freenode.net/spoj"><b>#spoj</b> at freenode</a>
		 </span>
	</td>
		<td class="cfooter" style="text-align: right;" width="10%">
		<a href="https://www.spoj.pl/rss/"><img src="spoj-04908_archivos/rss10x10.gif" border="0">&nbsp;RSS</a>&nbsp;
	
	</td>
    </tr>
    </tbody></table>
    </td></tr></tbody></table>
</center>
<div style="font-size: 10px; margin-top: 4px; color: rgb(85, 80, 95);"><center>
<a href="http://www.spoj.pl/" style="color: black;">SPOJ</a>
System &#169; 2008-2009
<a href="http://sphere-research.com/" style="color: black;">Sphere Research Labs</a>. 
All Rights Reserved.</center></div>


<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script><script src="spoj-04908_archivos/ga.js" type="text/javascript"></script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-10507872-1");
pageTracker._trackPageview();
} catch(err) {}</script>


<div id="hidden" style="visibility: hidden;"></div></body></html>